package com.itheima.demo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Demo_Iterator {
    public static void main(String[] args) {
        /*
        boolean hasNext()  ： 判断是否还有元素
        E next()  ： 获取元素并指针下移
        remove() : 删除元素
         */
        Collection<String> collection = new ArrayList<>();
        collection.add("aaa");
        collection.add("bbb");
        collection.add("ccc");
        collection.add("ddd");
        Iterator<String> it = collection.iterator();
        //boolean b = it.hasNext();
        //System.out.println(b);
        //String s = it.next();
        //System.out.println(s);
        System.out.println(collection);
        while (it.hasNext()){
            String s = it.next();
            if("ccc".equals(s)){
                it.remove();
            }
        }
        System.out.println(collection);
    }
}
